package com.tech.view.component.input;

import com.tech.view.common.SwingTestUtils;

import javax.swing.*;
import java.awt.*;

/**
 * label和数字输入框的简单组合
 */
public class LabelIntegerInputField extends JComponent {
	private String title;
	private IntegerInputField integerInputField;

	public LabelIntegerInputField(String title) {
		this.title = title;
		integerInputField = new IntegerInputField();
		init();
	}

	public static void main(String[] args) {
		SwingTestUtils.loadSkin();
		LabelIntegerInputField inputField = new LabelIntegerInputField("原价原价");
		JButton button = new JButton("获取");
		button.addActionListener(e -> System.out.println(inputField.getNum()));
		SwingTestUtils.test(inputField, button);
	}

	private void init() {
		setLayout(new BorderLayout());
		JLabel label = new JLabel(title);
		label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
		label.setFont(label.getFont().deriveFont(15f));
		add(label, BorderLayout.WEST);
		add(integerInputField);
	}

	public int getNum() {
		return integerInputField.getNum();
	}

	public void setNum(int num) {
		integerInputField.setNum(num);
	}

	public String getText() {
		return integerInputField.getText();
	}

	public String getTitle() {
		return title;
	}

	public IntegerInputField getIntegerInputField() {
		return integerInputField;
	}

}
